<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2016-6-21
 * Func   后台首页
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$a = NoBadStr($_REQUEST['a']);
if($a == 'main')
{
    $today = strtotime(date('Y-m-d'));
	
	$num = [];
	
	//	今日注册量
	$tmp = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('user').' WHERE reg_time > '.$today);
	$num['useradd'] = intval($tmp['p']);
	
	//	总人数
	$tmp = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('user').' WHERE 1');
	$num['userall'] = intval($tmp['p']);
	
	//	今日投注
	$tmp = $db->getrow('SELECT SUM(money) AS p FROM '.Table('lottery_order_list').' WHERE dateline > '.$today);
	$num['orderadd'] = round($tmp['p'],2);
	
	//	今日充值
	$tmp = $db->getrow('SELECT SUM(money) AS p FROM '.Table('user_money_recharge').' WHERE status = 1 AND dateline > '.$today);
	$num['rechargeadd'] = round($tmp['p'],2);
	
	//	今日提现
	$tmp = $db->getrow('SELECT SUM(money) AS p FROM '.Table('user_money_cash').' WHERE dateline > '.$today);
	$num['cashadd'] = round($tmp['p'],2);
	
	//	总返点
	$tmp = $db->getrow('SELECT SUM(money) AS p FROM '.Table('user_money_rebate'));
	$num['rebateall'] = round($tmp['p'],2);
	
	//	本次登录和上次登录
	$login = $db->getall('SELECT * FROM '.Table('admin_user_login').' WHERE username = \''.$_SESSION['admin']['username'].'\' AND status = 1 ORDER BY id DESC LIMIT 2');
	//	ip
	include_once(LIB_PATH.'class/Qqwry.class.php');
	$qqwry = new Qqwry();
	if($login[0])
	{
		$t2 = $qqwry->getlocation($login[0]['ip']);
		$login[0]['ip'] .= '('.$t2['country'].' '.$t2['area'].')';
	}
	if($login[1])
	{
		$t2 = $qqwry->getlocation($login[1]['ip']);
		$login[1]['ip'] .= '('.$t2['country'].' '.$t2['area'].')';
	}

    $tpl->display('index/index_main');
    exit();
}

$gid = '';
if($_Y['user']['gid'] > 1)
{
	!$_Y['group']['permit'] && exit();
	
	$gid = ' AND id IN ('.$_Y['group']['permit'].') ';
}

$menu = []; 
$tmp = $db->getall('SELECT * FROM '.Table('admin_menu').' WHERE pid = 0 '.$gid.' ORDER BY sort DESC');
foreach($tmp as $val)
{
	$val['sons'] = [];
	if($val['son'])
	{
		$val['sons'] = $db->getall('SELECT * FROM '.Table('admin_menu').' WHERE pid = '.$val['id'].' AND hide = 0 '.$gid.' ORDER BY sort DESC');
	}
	if($val['sons'])
	{
		foreach($val['sons'] as &$row)
		{
			$row['sons'] = $db->getall('select * from '.Table('admin_menu').' where pid = '.$row['id'].' and hide = 0 '.$gid.' order by sort desc');
		}
	}
	$menu[] = $val;
}
$tpl->display('index/index');

?>